package com.southwind.springboottest.study.java中流式操作;

import org.apache.tomcat.util.http.fileupload.util.Streams;

import java.util.ArrayList;
import java.util.Collections;
import java.util.stream.Stream;

/**
 * @description：TODO
 * @author： HXG
 * @create： 2024/3/19 17:17
 */
public class StreamDemo7 {
    public static void main(String[] args) {
        /**
         * distinct 元素去重，依赖(hashcode和equals方法)
         * concat 合并a和b两个流为一个流
         *
         * 注意1:中间方法，返回新的stream流，原来的stream流只能使用一次，建议使用链式编程
         * 注意2:修改stream流中的数据，不会影响原来集合或者数组中的数据
         */

        ArrayList<String> list1 = new ArrayList<>();
        Collections.addAll(list1,"张无忌","张无忌","张无忌","张无忌","张强","张三丰","张翠山","张良","王二麻子","谢广坤");

        ArrayList<String> list2 = new ArrayList<>();
        Collections.addAll(list2,"周芷若","赵敏");
        //去重
//        list1.stream().distinct().forEach(s -> System.out.println(s));
        Stream.concat(list1.stream(),list2.stream()).forEach(s -> System.out.println(s));

    }
}
